$(function(){
		//点击添加选中效果
		$("body").on("click",".zs-template-item",function(){
			var $this = $(this);
			if($this.hasClass("current")){
				$this.removeClass("current");
				$this.find(".cur").remove();
			}else{
				$this.addClass("current");
				var templateHtml = '<em class="cur"></em>';
				$this.append(templateHtml);
			}
		})
		
		//删除item
		$("body").on("click",".zs-template-div .close",function(){
			$(this).parent().remove();
		})
		
		//整数类型  
		$("body").on("keyup",".integerInput",function(){
			keyUpForInteger(this);
		});
		//小数类型 （2位）
		$("body").on("keyup",".floatInput",function(){
			keyUpForFloat(this);
		});
		//小数类型 （8位）
		$("body").on("keyup",".floatInput2",function(){
			keyUpForFloatForEigth(this);
		});
		$("body").on("keypress",".integerInput,.floatInput",function(){
			keyPress(this);}
		);
		$("body").on("blur",".integerInput,.floatInput",function(){
			onBlur(this);}
		);
		//去空格  wucuiyun 2017/2/13 15:26
		$("body").on("blur",".trimInput",function(){
			removeAllSpace(this);
		});
		
		$("body").on('click',".newTab",function(){
			var url = $(this).attr("data-url");
			var title = $(this).attr("title");
			page(url,title);// 如果非要以传参的形式的话就这样写，如果不需要直接把page里面的东西拿到onclick事件的回调函数中就可以了
		});
})

function page(url,title){
	var _parent = $("#content-main", parent.document); 
	_parent.find(".J_iframe").hide();
	_parent.find(".J_iframe").removeClass("active");
	var length = _parent.find(".J_iframe").length+100;
	_parent.append('<iframe class="J_iframe" name="iframe'+ length +'" width="100%" height="100%" src="'+ url +'" frameborder="0" data-id="' + url + '" seamless=""></iframe>');
	var _tab = $('.J_menuTabs .page-tabs-content ', parent.document);
	_tab.find(".J_menuTab").removeClass("active");
	_tab.append(' <a href="javascript:;" class="J_menuTab active" data-id="'+url+'">'+title+' <i class="fa fa-times-circle"></i></a>');
}
function keyPress(ob) {
	if (!ob.value.match(/^[\+\-]?\d*?\.?\d*?$/)) ob.value = ob.t_value; else ob.t_value = ob.value; if (ob.value.match(/^(?:[\+]?\d+(?:\.\d+)?)?$/)) ob.o_value = ob.value;
}
function keyUpForFloat(ob) {
	
	if (!ob.value.match(/^[\+]?\d*?\.?\d*?$/)) ob.value = ob.t_value; else ob.t_value = ob.value; 
	if (ob.value.match(/^(?:[\+]?\d+(?:\.\d+)?)?$/)) ob.o_value = ob.value;
	ob.value = ob.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')
	if(isNaN(ob.value)){
			ob.value = '';
	}
}
//允许输入8位小数
function keyUpForFloatForEigth(ob) {
	
	if (!ob.value.match(/^[\+]?\d*?\.?\d*?$/)) ob.value = ob.t_value; else ob.t_value = ob.value; 
	if (ob.value.match(/^(?:[\+]?\d+(?:\.\d+)?)?$/)) ob.o_value = ob.value;
	ob.value = ob.value.replace(/^(\-)*(\d+)\.(\d\d\d\d\d\d\d\d).*$/,'$1$2.$3')
	if(isNaN(ob.value)){
			ob.value = '';
	}
}
function keyUpForInteger(ob) {
	if (!ob.value.match(/^[\+\-]?\d*?\.?\d*?$/)) ob.value = ob.t_value; else ob.t_value = ob.value; 
	if (ob.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/)) ob.o_value = ob.value;
	if(ob.value.length==1){
		ob.value=ob.value.replace(/[^0-9]/g,'')
	}else{
		ob.value=ob.value.replace(/\D/g,'')
	}
	if(isNaN(ob.value)){
		ob.value = '';
	}
	if(ob.value == ''){
		return ;
	}
	ob.value = parseInt(ob.value);
}
function onBlur(ob) {
	if(!ob.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?|\.\d*?)?$/))ob.value=ob.o_value;else{if(ob.value.match(/^\.\d+$/))ob.value=0+ob.value;if(ob.value.match(/^\.$/))ob.value=0;ob.o_value=ob.value};
}
//去空格 wucuiyun 2017/2/13 15:26
function removeAllSpace(str) {
	str.value = $.trim(str.value);
}